<?php

namespace App\Admin\Controllers;

use App\Models\GoldNew;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Controllers\AdminController;

class GoldNewsController extends AdminController
{
    protected $title = '金店素材';

    protected function grid()
    {
        $grid = new Grid(new GoldNew());

        $grid->column('id', 'ID');
        $grid->column('title', '标题');
        $grid->column('content', '内容');
        
        
        $grid->disableExport();
        $grid->disableRowSelector();
        
        $this->gridActions($grid);

        return $grid;
    }
    
    protected function gridActions(Grid $grid)
    {
	    $grid->actions(function (Grid\Displayers\Actions $actions) {
	    	$actions->disableView();
	    });
    }
    
    protected function form()
    {
        $form = new Form(new GoldNew());

        $form->text('title', '标题');
        $form->textarea('content', '内容')->rules('required');
        $form->radio('type', '类型')->options(config('site.news'))
        ->when('video', function (Form $form) { 
            $form->image('video_image', '视频图');

        });
        $form->file('file_url', '图片或视频')->uniqueName()->rules('required');
        $form->radio('is_disabled', '使用')->options(config('site.bool'))->default(true);

        $this->formTools($form);
        $this->formFooter($form);

        return $form;
    }
    
    protected function formTools(Form $form)
    {
    	$form->tools(function (Form\Tools $tools) {
		    $tools->disableView();
	    });
    }
    
    protected function formFooter(Form $form)
    {
	    $form->footer(function (Form\Footer $footer) {
		    $footer->disableViewCheck();
		    $footer->disableCreatingCheck();
		    $footer->disableEditingCheck();
	    });
    }
}
